<template>
    <div class="ehcart" ref="echart"></div>
</template>
<style media="screen">
.ehcart{
    height:100%;width:100%;
}
</style>
<script>
// import chinaJson from '@/assets/json/china.json'

var echarts = require('echarts');
// require('echarts/extension/bmap/bmap');
// var bmap = this.myChart.getModel().getComponent('bmap').getBMap();
// import bmap from 'echarts/extension/bmap/bmap';

export default {
    name: 'work-ehcart',
    data: function () {
        return {
            tableHeight: '',
            linOption: true,
            NOMAPOPTION: []
        }
    },
    props: {
        options: {
            type: Object
        }

    },
    watch: {
        options: function (newOptions) {
            console.log(newOptions);
            // this.NOMAPOPTION = newOptions
            // this.myChart.setOption(this.NOMAPOPTION);
            // if (newOptions.bmap === undefined) {
            //     this.myChart.dispose()
            //     this.myChart = echarts.init(this.$refs.echart);
            //     this.myChart.setOption(this.NOMAPOPTION);
            //     this.resize()
            // } else {
            //     this.myChart.clear()
            this.myChart.setOption(newOptions);
            this.resize()
            // }
        }
    },
    created () {
        // this.getTableData(this.page);
    },
    mounted () {
        // 动态设置高度
        // this.tableHeight = getRemainingHeight(this.$refs.echart)
        this.myChart = echarts.init(this.$refs.echart);
        console.log(this.options);
        if (this.options !== null&&this.options!== undefined) {
            this.myChart.setOption(this.options)
            var that = this
            window.onresize = function() {
                that.resize()
            }
        }
        // echarts.registerMap('china', chinaJson);
        // if (this.options.legend.data[0] !== 'start') {
        //     this.myChart.setOption(this.options)
        // }
        // 百度地图
        // var bmap = this.myChart.getModel().getComponent('bmap').getBMap();
        // bmap.addControl(new BMap.MapTypeControl());
    },
    methods: {
        resize () {
            this.myChart.resize();
        },
        clearChart () {
            this.myChart.clear()
        },
        clearBmp () {
            this.myChart.resize()
            // this.myChart.setOption(this.newOptions = {
            //     visualMap: {
            //         show: false
            //     }
            // });
        }
    }
}
</script>
